import pygame, sys
import menu, script, map

class Game:

	def __init__(self):
		self.loading_fnt = 	self.fnt = pygame.font.Font("resources/menu/xfiles.ttf",32)
		self.screen = pygame.display.set_mode((800,600),pygame.FULLSCREEN,16)
		#self.dx = 0
		self.poll = 0
		#self.dy = 0
		self.quit = 0
		self.curmap = 0
		self.time = 0
		self.map_list = []
		self.draw_loading_screen("Building Menu")
		self.main_menu = menu.Menu("0",50,"traditional")
		self.selection_menu = menu.Menu("1",50,"selection")
		self.mode = 0
		main_script = script.Script("resources/main.txt")
		self.nummaps = main_script.get_nvalue("MAPNUM","int","=")
		self.global_points = 0
		# 0 - Locked, 1 - Unlocked, 2 - Completed
		self.level_status = [1,0,0,0,0,0,0,0,0,0,0,0,0]
		for i in range(0, self.nummaps):
			tmp_map = map.Map(self,i)
			self.map_list.append(tmp_map)
	
	def update_time(self, time):
		self.time = time
	
	def draw_loading_screen(self,message):
		self.screen.fill((0,0,0))
		tmp_surface = self.fnt.render(message,True,(255,0,0))
		tmp_surface2 = self.fnt.render("Loading...",True,(0,255,0))
		self.screen.blit(tmp_surface,(100,100))
		self.screen.blit(tmp_surface2,(0,0))
		pygame.display.flip()
		
	def manage_menu(self,poll):
		if self.mode == 0:
			v = self.main_menu.do_action(self)
			if v == "Start":
				self.mode = 2
			elif v == "Exit":
				self.quit = 1
		elif self.mode == 2:
			pygame.mouse.set_visible(True)
			v = self.selection_menu.do_action(self)
			if v >= 0 or v <> None:
				pygame.mouse.set_visible(False)
				self.curmap = v
				self.mode = 1
			
			
	def check_quit(self):
		if self.quit == 1:
			return True
		else:
			return False
	
	def draw_game(self):
		self.map_list[self.curmap].del_surface()
		self.map_list[self.curmap].get_time(self.time)
		self.map_list[self.curmap].get_poll(self.poll)
		self.poll = self.map_list[self.curmap].set_poll()
		return self.map_list[self.curmap].draw(self)
		
			